<template>
  <!-- 重置密码 表单 -->
  <a-modal
    v-model:open="visible"
    title="重置密码"
    class="addStation"
    destroyOnClose
    :width="520"
    @cancel="cancel"
    centered
  >
    <div class="resetPassWord">初始密码为{{defaultPwd}}，是否将账号重置为初始密码？</div>
    <template #footer>
      <div class="footerBar">
        <a-button key="back" @click="cancel">取消</a-button>
        <a-button
          key="submit"
          type="primary"
          :loading="loading"
          @click="handleSubmit"
          >确认</a-button
        >
      </div>
    </template>
  </a-modal>
</template>
<script setup>


const $api = inject("$api");
const props = defineProps({
  resetPassWordVisible: {
    type: Boolean,
    default: false,
  },
  rowData: {
    type: Object,
  },
});
const loading = ref(false);
const visible = ref(props.resetPassWordVisible);
const emits = defineEmits(["update:resetPassWordVisible","getUserList"]);
watch(
  () => props.resetPassWordVisible,
  (val) => {
    visible.value = val;
    if (val) {
      getuserDefaultPwd();
    }
  }
);
const cancel = () => {
  emits("update:resetPassWordVisible", false);
};
const defaultPwd = ref('-');
const getuserDefaultPwd = async () => {
  const res = await $api.userDefaultPwd({
    account: props.rowData.account,
    username: props.rowData.username
  });
  defaultPwd.value = res?.data;
};
const handleSubmit = async () => {
  const params = {
    userType: 1, // 1：内部用户 2：企业主账号 3：企业子账号
  }
  const res = await $api.userResetPwd(props.rowData.id, params);
  if (res && res.code === 0) {
    message.success("重置成功");
    cancel();
    emits('getUserList')
  }
};
</script>

<style lang="less" scoped>
.resetPassWord {
  margin: 24px;
  font-size: 16px;
}
.footerBar {
  text-align: center;
  margin-top: 30px;
}
</style>